package com.liu.stockmarket.ui.datacenter.ui.newbond

import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.liu.stockmarket.R
import com.liu.stockmarket.model.NewBond
import com.liu.stockmarket.utils.*
import java.math.BigDecimal

class NewBondAdapter : BaseQuickAdapter<NewBond, BaseViewHolder>(R.layout.item_new_bond),
    LoadMoreModule {
    override fun convert(holder: BaseViewHolder, item: NewBond) {
        val publicStartDate = item.PUBLIC_START_DATE.substring(0, 10).YMDParse()
        val shanghai = item.TRADE_MARKET == "CNSESH"
        holder.setText(R.id.tv_name_and_code, "${item.SECURITY_NAME_ABBR}(${item.SECURITY_CODE})")
            .setText(
                R.id.tv_market,
                if (shanghai) context.getString(R.string.sh) else context.getString(
                    R.string.sz
                )
            ).setBackgroundColor(
                R.id.tv_market, if (shanghai) context.getColor(R.color.SH)
                else context.getColor(R.color.SZ)
            )

            .setText(R.id.tv_actual_issue_scale, item.ACTUAL_ISSUE_SCALE.moneyFormat())
            .setText(R.id.tv_rating, item.RATING)
            .setText(
                R.id.tv_now_price,
                item.CURRENT_BOND_PRICENEW ?: item.CURRENT_BOND_PRICE
            ).setText(
                R.id.tv_public_start_date,
                item.PUBLIC_START_DATE.substring(5, 10) + " " + publicStartDate.week()
            )
            .setText(R.id.tv_listing_date, item.LISTING_DATE?.let {
                it.substring(5, 10) + " " + it.substring(0, 10).YMDParse().week()
            }?: "未公布")

        holder.getView<TextView>(R.id.tv_transfer_premium_ratio)
            .percent(this.context, BigDecimal(item.TRANSFER_PREMIUM_RATIO ?: "0"))
    }

}